package cn.blunce;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;

public class DBGen {
    public static void main(String[] args) throws Exception {
//        System.out.printf("Test");

        Schema schema = new Schema(1, "cn.blunce.weather.models");

        schema.enableKeepSectionsByDefault();//add custom code

        addCities(schema);
        addWeatherID(schema);
        addWeatherMessage(schema);

        new DaoGenerator().generateAll(schema, "../app/src/main/java");
    }

    private static void addCities(Schema schema) {
        Entity entity = schema.addEntity("CityID");
        entity.addStringProperty("id").primaryKey();
        entity.addStringProperty("city");
        entity.addStringProperty("cnty");
        entity.addDoubleProperty("lat");
        entity.addDoubleProperty("lon");
        entity.addStringProperty("prov");
    }

    private static void addWeatherID(Schema schema) {
        Entity entity = schema.addEntity("WeatherID");
        entity.addStringProperty("code").primaryKey();
        entity.addStringProperty("txt");
        entity.addStringProperty("txt_en");
        entity.addStringProperty("icon");
    }

    private static void addWeatherMessage(Schema schema) {
        Entity weather_message = schema.addEntity("WeatherMessage");
        weather_message.addIdProperty();
        weather_message.addStringProperty("city_id");
        weather_message.addStringProperty("update");//local time

        //******************************************************************************************
        Entity weather_aqi = schema.addEntity("WeatherAQI");
        weather_aqi.addIdProperty();
        weather_aqi.addDoubleProperty("aqi");
        weather_aqi.addDoubleProperty("co");
        weather_aqi.addDoubleProperty("no2");
        weather_aqi.addDoubleProperty("o3");
        weather_aqi.addDoubleProperty("pm10");
        weather_aqi.addDoubleProperty("pm25");
        weather_aqi.addStringProperty("qlty");
        weather_aqi.addDoubleProperty("so2");

        Property property_message_to_aqi = weather_message.addLongProperty("aqi_ID").getProperty();
        weather_message.addToOne(weather_aqi, property_message_to_aqi, "aqi");
        //******************************************************************************************

        Entity daily_forcast = schema.addEntity("DailyForcast");
        daily_forcast.addIdProperty();

        Entity astro_weather = schema.addEntity("AstroWeather");
        astro_weather.addIdProperty();
        astro_weather.addStringProperty("mr");
        astro_weather.addStringProperty("ms");
        astro_weather.addStringProperty("sr");
        astro_weather.addStringProperty("ss");
        Property property_daily_forcast_to_astro = daily_forcast.addLongProperty("astro_ID").getProperty();
        daily_forcast.addToOne(astro_weather, property_daily_forcast_to_astro, "astro");

        Entity weather_daily = schema.addEntity("WeatherDaily");
        weather_daily.addIdProperty();
        weather_daily.addStringProperty("code_d");
        weather_daily.addStringProperty("code_n");
        weather_daily.addStringProperty("txt_d");
        weather_daily.addStringProperty("txt_n");
        Property property_daily_forcast_to_weather_daily = daily_forcast.addLongProperty("cond_ID").getProperty();
        daily_forcast.addToOne(weather_daily, property_daily_forcast_to_weather_daily, "cond");

        daily_forcast.addStringProperty("date");
        daily_forcast.addDoubleProperty("hum");
        daily_forcast.addDoubleProperty("pcpn");
        daily_forcast.addDoubleProperty("pop");
        daily_forcast.addDoubleProperty("pres");
        daily_forcast.addDoubleProperty("vis");

        Entity weather_tmp = schema.addEntity("WeatherTmp");
        weather_tmp.addIdProperty();
        weather_tmp.addDoubleProperty("max");
        weather_tmp.addDoubleProperty("min");
        Property property_daily_forcast_to_weather_tmp = daily_forcast.addLongProperty("tmp_ID").getProperty();
        daily_forcast.addToOne(weather_tmp, property_daily_forcast_to_weather_tmp, "tmp");

        Entity weather_wind = schema.addEntity("WeatherWind");
        weather_wind.addIdProperty();
        weather_wind.addDoubleProperty("deg");
        weather_wind.addStringProperty("dir");
        weather_wind.addStringProperty("sc");
        weather_wind.addDoubleProperty("spd");
        Property property_daily_forcast_to_weather_wind = daily_forcast.addLongProperty("wind_ID").getProperty();
        daily_forcast.addToOne(weather_wind, property_daily_forcast_to_weather_wind, "wind");

        //one to many
        Property property_daily_forcast_to_weather_meassage = daily_forcast.addLongProperty("weather_message_id").getProperty();
        weather_message.addToMany(daily_forcast, property_daily_forcast_to_weather_meassage).setName("daily_forcasts");
        //******************************************************************************************

        Entity hourly_forcast = schema.addEntity("HourlyForcast");
        hourly_forcast.addIdProperty();
        hourly_forcast.addStringProperty("date");
        hourly_forcast.addDoubleProperty("hum");
        hourly_forcast.addDoubleProperty("pres");
        hourly_forcast.addDoubleProperty("pop");
        hourly_forcast.addDoubleProperty("tmp");

        Property property_hourly_forcast_to_weather_wind = hourly_forcast.addLongProperty("wind_ID").getProperty();
        hourly_forcast.addToOne(weather_wind, property_hourly_forcast_to_weather_wind, "wind");

        //one to many
        Property property_hourly_forcast_to_weather_message = hourly_forcast.addLongProperty("weather_message_id").getProperty();
        weather_message.addToMany(hourly_forcast, property_hourly_forcast_to_weather_message).setName("hourly_forcasts");

        //******************************************************************************************

        Entity weather_now = schema.addEntity("WeatherNow");
        weather_now.addIdProperty();
        weather_now.addDoubleProperty("tmp");
        weather_now.addDoubleProperty("pcpn");
        weather_now.addDoubleProperty("f1");
        weather_now.addDoubleProperty("hum");
        weather_now.addDoubleProperty("pres");
        weather_now.addDoubleProperty("vis");

        Property property_weather_now_to_wind = weather_now.addLongProperty("wind_ID").getProperty();
        weather_now.addToOne(weather_wind, property_weather_now_to_wind, "wind");

        Entity now_cond = schema.addEntity("WeatherNowCond");
        now_cond.addIdProperty();
        now_cond.addStringProperty("code");
        now_cond.addStringProperty("txt");

        Property property_weather_now_to_now_cond = weather_now.addLongProperty("cond_now_ID").getProperty();
        weather_now.addToOne(now_cond, property_weather_now_to_now_cond, "cond_now");

        Property property_weather_message_to_weather_now = weather_message.addLongProperty("now_ID").getProperty();
        weather_message.addToOne(weather_now, property_weather_message_to_weather_now, "now");

        //******************************************************************************************
        Entity weather_suggestion = schema.addEntity("WeatherSuggestion");
        weather_suggestion.addIdProperty();

        Entity suggestion = schema.addEntity("Suggestion");
        suggestion.addIdProperty();
        suggestion.addStringProperty("brf");
        suggestion.addStringProperty("txt");

        Property property_weather_suggestion_to_comf = weather_suggestion.addLongProperty("comf_ID").getProperty();
        weather_suggestion.addToOne(suggestion, property_weather_suggestion_to_comf, "comf");

        Property property_weather_suggestion_to_cw = weather_suggestion.addLongProperty("cw_ID").getProperty();
        weather_suggestion.addToOne(suggestion, property_weather_suggestion_to_cw, "cw");

        Property property_weather_suggestion_to_drsg = weather_suggestion.addLongProperty("drsg_ID").getProperty();
        weather_suggestion.addToOne(suggestion, property_weather_suggestion_to_drsg, "drsg");

        Property property_weather_suggestion_to_flu = weather_suggestion.addLongProperty("flu_ID").getProperty();
        weather_suggestion.addToOne(suggestion, property_weather_suggestion_to_flu, "flu");

        Property property_weather_suggestion_to_sport = weather_suggestion.addLongProperty("sport_ID").getProperty();
        weather_suggestion.addToOne(suggestion, property_weather_suggestion_to_sport, "sport");

        Property property_weather_suggestion_to_traw = weather_suggestion.addLongProperty("traw_ID").getProperty();
        weather_suggestion.addToOne(suggestion, property_weather_suggestion_to_traw, "traw");

        Property property_weather_suggestion_to_uv = weather_suggestion.addLongProperty("uv_ID").getProperty();
        weather_suggestion.addToOne(suggestion, property_weather_suggestion_to_uv, "uv");

        Property property_weather_message_to_weather_suggestion = weather_message.addLongProperty("suggestion_ID").getProperty();
        weather_message.addToOne(weather_suggestion, property_weather_message_to_weather_suggestion, "suggestion");
    }
}
